/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-09 07:33:10
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-24 14:58:12
 */
import 'package:flutter/material.dart';
import 'package:flutter_inner_drawer/inner_drawer.dart';
import 'package:google_fonts/google_fonts.dart';

import '../../../constrans.dart';
import 'message_right_item.dart';
import 'bottom_blur.dart';
import 'bottom_nav.dart';
import 'message_card.dart';
import 'notice_list.dart';
import 'start_room.dart';

class MessageBody extends StatefulWidget {
  const MessageBody({
    Key key,
  }) : super(key: key);

  @override
  _MessageBodyState createState() => _MessageBodyState();
}

class _MessageBodyState extends State<MessageBody> {
  final GlobalKey<InnerDrawerState> _innerDramerKey =
      GlobalKey<InnerDrawerState>();
  bool isToggle = false;

  void _toggle() {
    _innerDramerKey.currentState?.toggle(direction: InnerDrawerDirection.end);
    setState(() {
      isToggle = !isToggle;
    });
  }

  Future<void> onRefreshDrawerList() async {
    await Future.delayed(Duration(milliseconds: 500));
  }

  Future<void> onRefreshRoomList() async {
    await Future.delayed(Duration(milliseconds: 1000));
  }

  @override
  Widget build(BuildContext context) => Positioned(
        bottom: 54,
        top: 48,
        left: 0,
        right: 0,
        child: InnerDrawer(
          scale: const IDOffset.horizontal(0.8),
          rightAnimationType: InnerDrawerAnimation.linear,
          offset: IDOffset.horizontal(0.5),
          key: _innerDramerKey,
          colorTransitionChild: Colors.transparent,
          colorTransitionScaffold: Colors.transparent,
          swipe: true, // default true
          swipeChild: false,
          onTapClose: true,
          boxShadow: [],
          innerDrawerCallback: (value) {
            setState(() {
              isToggle = value;
            });
          },
          backgroundDecoration: BoxDecoration(
            color: appBackgroundColor,
          ),
          rightChild: RefreshIndicator(
            onRefresh: onRefreshDrawerList,
            child: Padding(
              padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
              child: Column(
                children: [
                  Expanded(
                    flex: 1,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Text(
                            "AVAILBLE TO CHAT",
                            style: TextStyle(
                              fontSize: 12,
                              color: Colors.brown[200],
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                        Expanded(
                          child: Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: Divider(
                              height: 0,
                              thickness: 1.2,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                    flex: 15,
                    child: ListView.builder(
                      physics: BouncingScrollPhysics(),
                      itemCount: 30,
                      itemBuilder: (context, index) => MessageRightItem(),
                    ),
                  ),
                ],
              ),
            ),
          ),
          scaffold: Scaffold(
            backgroundColor: appBackgroundColor,
            body: Stack(
              children: [
                Container(
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      colors: [
                        appBackgroundColor,
                        appBackgroundColor.withOpacity(0.5),
                        Colors.white.withOpacity(0.2),
                      ],
                      begin: Alignment.bottomCenter,
                      end: Alignment.topCenter,
                    ),
                  ),
                  child: RefreshIndicator(
                    onRefresh: onRefreshRoomList,
                    child: ListView.builder(
                      shrinkWrap: true,
                      itemCount: 10,
                      physics: BouncingScrollPhysics(),
                      itemBuilder: (context, index) =>
                          index == 0 ? NoticeList() : MessageCard(index: index),
                    ),
                  ),
                ),
                BottomBlur(),
                StartRoom(
                  onTap: _toggle,
                  showIcon: isToggle,
                ),
              ],
            ),
          ),
        ),
      );
}
